package puzzle.projecteuler.p100;

public class Problem039 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int P = 0;
		int C = 0;
		for (int p = 1; p < 1000; p ++) {
			int c = count(p); 
			if (c > C) {
				P = p;
				C = c;
			}
		}
		System.out.println(P);
		System.out.println(C);
	}

	public static int count(int p) {
		if (p%2 == 1) {
			return 0;
		} else {
			int lower = (int)Math.ceil((Math.sqrt(2)-1)*p);
			int upper = p/2-1;
			int s = 0;
			for (int c = lower; c <= upper; c ++) {
				int m = 2*c*c - (p-c)*(p-c);
				int t = (int)Math.floor(Math.sqrt(m));
				if (t*t == m) {
					s ++;
//					System.out.println(c);
				}
			}
			return s;
		}
	}
}
